package com.tanjun.mallservice.web.controller.shopcar;

import com.tanjun.common.model.R;
import com.tanjun.mallservice.apiservice.request.shopcar.DelShopCarVo;
import com.tanjun.mallservice.apiservice.request.shopcar.SetShopCarVo;
import com.tanjun.mallservice.apiservice.response.shopcar.MallShopCarDto;
import com.tanjun.mallservice.web.biz.MallShopCarBiz;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

import static com.tanjun.common.constants.UrlConstant.URL_USER.MEM;


@RestController
public class ShopCarController {
    private final String PREX = "/shopCar";
    @Autowired
    private MallShopCarBiz shopCarBiz;

    /**
     * 将商品添加到购物车
     *
     * @param paramVo
     */

    @PostMapping(MEM + PREX + "/changeShopCarNum")
    public R changeShopCarNum(@RequestBody @Validated SetShopCarVo paramVo) {
        shopCarBiz.changeShopCarNum(paramVo);
        return R.OK();
    }

    /**
     * 获取用户购物车详细列表
     *
     * @return 返回物资列表
     */
    @GetMapping(MEM + PREX + "/getListShopCarDetail")
    public R<List<MallShopCarDto>> getListShopCarDetail() {
        return R.OK(shopCarBiz.getListShopCarDetail());
    }

    /**
     * 统计用户购物车有多少件不同规格商品
     *
     * @return 数量
     */
    @GetMapping(MEM + PREX + "/countShopCarSkuNum")
    public R<Integer> countShopCarSkuNum() {
        return R.OK(shopCarBiz.countShopCarSkuNum());
    }

    /**
     * 删除购物车商品
     * @param paramVo
     * @return
     */
    @PostMapping(MEM + PREX + "/deleteShopCar")
    public R deleteShopCar(@RequestBody @Validated DelShopCarVo paramVo){
        shopCarBiz.deleteShopCar(paramVo);
        return R.OK();
    }
}
